package com.estate;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.estate.common.utils.redis.RedisUtil;
import com.estate.system.domain.Buy;
import com.estate.system.mapper.*;
import com.estate.system.service.IBuyService;
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

/**
 * 启动程序
 * 
 * @author estate
 */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
    public class EstateApplication implements CommandLineRunner
{


    @Resource
    BuyDetailMapper buyDetailMapper;
    @Resource
    SecondHandDetailMapper secondHandDetailMapper;
    @Resource
    ApartmentDetailMapper apartmentDetailMapper;
    @Resource
    UrgentHouseDetailMapper urgentHouseDetailMapper;
    @Resource
    IntroductionDetailMapper introductionDetailMapperl;
    @Resource
    BuyMapper buyMapper;
    @Resource
    CarouselDetailMapper carouselDetailMapper;
    @Resource
    CarouselMapper carouselMapper;
    @Resource
    IBuyService buyService;
    @Resource
    RedisUtil redisUtil;
    @Resource
    RedisTemplate redisTemplate;




    public static void main(String[] args)
    {

        // System.setProperty("spring.devtools.restart.enabled", "false");
        ApplicationContext run = (ApplicationContext)SpringApplication.run(estateApplication.class, args);


    }


    @Override
    public void run(String... args) throws Exception {
//       //完全使用redis好了
//        PageInfo<Buy> buyPageInfo = buyService.selectAllBuyList(10, 1);
//        buyPageInfo.setPageSize(10);
//        buyPageInfo.setPageNum(1);
//        System.out.println("list:"+buyPageInfo);
        redisTemplate.setKeySerializer(redisTemplate.getStringSerializer());
        //@bean方式将K设为String序列化后，V会自动转为String序列化。
        // 为了保持Object类型的V值，故我这边需将V设回默认的jdk的V，
        redisTemplate.setValueSerializer(redisTemplate.getDefaultSerializer());

        Set keys = redisTemplate.keys("*");
        redisTemplate.delete(keys);

    }
}